﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.NetworkInformation;
using System.Text;

namespace LCL.XPing
{
    public class PingData
    {
        private string swebsite;
        private string sip;
        private string sping;
        private string savg;
        private string serr;
        private string savgTag;
        public string website
        {
            get
            {
                return this.swebsite;
            }
            private set
            {
                this.swebsite = value;
            }
        }
        public string ip
        {
            get
            {
                return this.sip;
            }
            private set
            {
                this.sip = value;
            }
        }
        public string ping
        {
            get
            {
                return this.sping;
            }
            private set
            {
                this.sping = value;
            }
        }
        public string avg
        {
            get
            {
                return this.savg;
            }
            private set
            {
                this.savg = value;
            }
        }
        public string err
        {
            get
            {
                return this.serr;
            }
            private set
            {
                this.serr = value;
            }
        }
        public string avgTag
        {
            get
            {
                return this.savgTag;
            }
            private set
            {
                this.savgTag = value;
            }
        }
        public PingData(string name)
        {
            this.website = name;
            this.avgTag = "0|0";
            this.ip = "-";
            this.ping = "0";
            this.avg = "0";
            this.err = "0/0";
        }
        public void Update(PingReply reply)
        {
            this.ip = reply.Address.ToString();
            long num = reply.RoundtripTime;
            if (num == 0L)
            {
                this.ping = "<1ms";
            }
            else
            {
                this.ping = num.ToString() + "ms";
            }
            string[] array = this.avgTag.Split(new char[]
			{
				'|'
			});
            num = long.Parse(array[0]) + num;
            long num2 = long.Parse(array[1]) + 1L;
            this.avgTag = num.ToString() + "|" + num2.ToString();
            this.avg = (num / num2).ToString() + "ms";
            string[] array2 = this.err.ToString().Split(new char[]
			{
				'/'
			});
            long num3 = long.Parse(array2[0]);
            long num4 = long.Parse(array2[1]) + 1L;
            this.err = string.Format("{0}/{1}", num3, num4);
        }
        public void UpdateErr()
        {
            this.ping = "请求超时";
            string[] array = this.err.ToString().Split(new char[]
			{
				'/'
			});
            long num = long.Parse(array[0]) + 1L;
            long num2 = long.Parse(array[1]) + 1L;
            this.err = string.Format("{0}/{1}", num, num2);
        }
    }
}
